package com.xy.lang.util;

import sun.misc.BASE64Encoder;

import java.security.SecureRandom;

public class SecureUtils {

    private final static SecureRandom random = new SecureRandom();
    private final static BASE64Encoder base64Encoder = new BASE64Encoder();

    public static byte[] generateRandom(int length) {
        byte[] values = new byte[length];
        random.nextBytes(values);
        return values;
    }

    public static String generateRandomString(int length) {
        return base64Encoder.encode(generateRandom(length));
    }

    public static void main(String[] args) throws Exception {
        System.out.println(generateRandomString(10));
    }

}
